package com.softkey;

public class SoftKey {

	jsyunew3 j9;
	public SoftKey()
	{
		j9=new  jsyunew3();
	}

	private String myhex(byte indata)
	{
		String outString;
		outString=String.format("%X",indata);
		if(outString.length()<2)outString="0"+outString;
		return outString;
	}

    private  long conver(byte temp){
        long tempInt = (int)temp;
        if(tempInt < 0){
            tempInt += 256;
        }
        return tempInt;
    }

    private int HexToInt(String s)
    {
        String [] hexch = { "0", "1", "2", "3", "4", "5", "6", "7",
						       "8", "9", "A", "B", "C", "D", "E", "F"};
        int i, j;
        int r, n, k;
        String ch;

        k = 1; r = 0;
        for (i = s.length(); i > 0; i--)
        {
            ch = s.substring(i - 1,  i-1+1);
            n = 0;
            for (j = 0; j < 16; j++)
            {
                if (ch.compareToIgnoreCase(hexch[j]) ==0 )
                {
                    n = j;
                }
            }
            r += (n * k);
            k *= 16;
        }
        return r;
    }


    public String  StrEnc(String InString , String Key)
    {

        byte [] b,outb;
        byte []temp_b=InString.getBytes();
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString;

        nlen = temp_b.length;
        nlen=nlen+1;
        if( nlen < 8 )
            outlen = 8;
        else
            outlen = nlen;
        b=new byte[outlen];
        outb=new byte[outlen];

        for(n=0;n<nlen-1;n++)
        {
        	b[n]=temp_b[n];
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            EnCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString = "";
        for (n = 0 ;n<= outlen - 1;n++)
        {
            outString = outString +myhex(outb[n]) ;
        }
        return outString;
    }

    public String  StrDec(String InString , String Key)
    {

        byte [] b,outb;
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString,temp_String;


        nlen = InString.length();
        if( nlen < 16 ) outlen = 16;
        outlen = nlen / 2;
        b=new byte[outlen];
        outb=new byte[outlen];

        i = 0;
        for (n = 1 ;n<= nlen ;n=n+2)
        {
            temp_String = InString.substring(n-1, n-1+2);
            b[i] = (byte)HexToInt(temp_String);
            i = i + 1;
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            DeCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString=new String(outb);
        outString=outString.trim();
        return outString;
    }

	public void EnCode(byte[] inb, byte[] outb,  String Key )
    {

		long cnDelta,y,z,a,b,c,d,temp_2;
		long [] buf=new long[16];
       int n,i,nlen;
       long sum;
       long temp,temp_1;
       long mask=4294967295L;

       //UInt32 temp, temp_1;
       String temp_String ;


       cnDelta = 2654435769L;
       sum = 0;

       nlen = Key.length();
       i = 0;
       for( n = 1 ;n<= nlen ;n=n+2)
       {
           temp_String =Key.substring(n-1, n-1+2);
           buf[i] =HexToInt(temp_String);
           i = i + 1;
       }
       a = 0 ; b = 0 ; c = 0 ; d = 0;
       for(n = 0;n<=3;n++)
       {
           a = (buf[n] << (n * 8)) | a;
           b = (buf[n + 4] << (n * 8)) | b;
           c = (buf[n + 4 + 4] << (n * 8)) | c;
           d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
       }


       y = 0;
       z = 0;
       for(n = 0;n<=3;n++)
       {
           temp_2 = conver(inb[n]);
           y = (temp_2 << (n * 8)) | y;
           temp_2 = conver(inb[n + 4]);
           z = (temp_2 << (n * 8)) | z;
       }


       n = 32;

       while (n > 0)
       {
           sum = (cnDelta + sum)& mask;

           temp = (z << 4) & mask;
           temp = (temp + a) & mask;
           temp_1 = (z + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (z >> 5) & mask;
           temp_1 = (temp_1 + b) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (temp + y) & mask;
           y = temp & mask;

           temp = (y << 4) & mask;
           temp = (temp + c) & mask;
           temp_1 = (y + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (y >> 5) & mask;
           temp_1 = (temp_1 + d) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (z + temp) & mask;
           z = temp & mask;
           n = n - 1;

       }
       for(n = 0;n<=3;n++)
       {
           outb[n] = (byte)((y >>> (n * 8)) & 255);
           outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
       }
    }

	public void DeCode(byte[] inb, byte[] outb,  String Key )
    {

		long cnDelta,y,z,a,b,c,d,temp_2;
		long [] buf=new long[16];
       int n,i,nlen;
       long sum;
       long temp,temp_1;

       long mask=4294967295L;

       //UInt32 temp, temp_1;
       String temp_String ;


       cnDelta = 2654435769L;
       sum = 3337565984L;

       nlen = Key.length();
       i = 0;
       for( n = 1 ;n<= nlen ;n=n+2)
       {
           temp_String =Key.substring(n-1, n-1+2);
           buf[i] =HexToInt(temp_String);
           i = i + 1;
       }
       a = 0 ; b = 0 ; c = 0 ; d = 0;
       for(n = 0;n<=3;n++)
       {
           a = (buf[n] << (n * 8)) | a;
           b = (buf[n + 4] << (n * 8)) | b;
           c = (buf[n + 4 + 4] << (n * 8)) | c;
           d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
       }


       y = 0;
       z = 0;
       for(n = 0;n<=3;n++)
       {
           temp_2 = conver(inb[n]);
           y = (temp_2 << (n * 8)) | y;
           temp_2 = conver(inb[n + 4]);
           z = (temp_2 << (n * 8)) | z;
       }


       n = 32;

       while (n > 0)
       {


           temp = (y << 4) & mask;
           temp = (temp + c) & mask;
           temp_1 = (y + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (y >> 5) & mask;
           temp_1 = (temp_1 + d) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (z - temp) & mask;
           z = temp & mask;

           temp = (z << 4) & mask;
           temp = (temp + a) & mask;
           temp_1 = (z + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (z >> 5) & mask;
           temp_1 = (temp_1 + b) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (y - temp ) & mask;
           y = temp & mask;

           sum = (sum-cnDelta)& mask;
           n = n - 1;

       }
       for(n = 0;n<=3;n++)
       {
           outb[n] = (byte)((y >>> (n * 8)) & 255);
           outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
       }
    }

	public  long get_LastError()
	{
		return j9.get_LastError();
	}

	public String FindPort(int start)
    {
        return j9.FindPort(start);
    }

   public int CheckKeyByFindort_2()
    {
        String DevicePath = "";
		DevicePath = j9.FindPort_2(0, 1, -1554037726);
		int ret = (int)j9.get_LastError();
		j9.CloseUsbHandle(DevicePath);
		return ret;
    }


    private String ReadStringEx(int addr, String DevicePath)
    {
        int nlen, ret;
        byte[] buf = new byte[1];
		ret = j9.YReadEx((short)addr, (short)1, "67BEB92E", "57BD8D98", DevicePath);
        if (ret != 0) return "";
		nlen = j9.GetBuf(0);
		return j9.NewReadString(addr + 1, nlen, "67BEB92E", "57BD8D98", DevicePath);

    }
    public int CheckKeyByReadEprom()
    {
        int n, ret;
        String DevicePath = "";
        String outString = "";
        for (n = 0; n < 255; n++)
        {
            DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			outString = ReadStringEx(0, DevicePath);
			j9.CloseUsbHandle(DevicePath);
			if ((j9.get_LastError() == 0) && (outString.compareTo("ABC") == 0))
			{
				return 0;
			}
        }
        return -92;
    }
    public int CheckKeyByEncstring()
    {

        int n, ret;
        String DevicePath = "";
        String InString;

        int number1=(int)(Math.random()*65535)+1;
        int number2=(int)(Math.random()*65535)+1;

        InString = (new   Integer(number1)).toString() + (new   Integer(number2)).toString();

        for (n = 0; n < 255; n++)
        {
           DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			if (Sub_CheckKeyByEncString(InString, DevicePath) == 0)
			{
				return 0;
			}
        }
        return -92;
    }

    private int Sub_CheckKeyByEncString(String InString, String DevicePath)
    {
        int ret;
        String outString = "";
        String outString_2;
		outString = j9.EncString(InString,DevicePath);
		if (j9.get_LastError() != 0) return (int)j9.get_LastError();
		outString_2 = StrEnc(InString, "71B1FC0D3CCF4A5DE7EC2DFD6E9B64A7");
        if (outString_2.compareTo(outString) == 0)
        {
            ret = 0;
        }
        else
        {
            ret = -92;
        }
        j9.CloseUsbHandle(DevicePath);
        return ret;
    }


	public int CheckKeyByEncstring_New()
	{
		int n, ret;
		String DevicePath = "";
		String outString = "";
		int myrnd = (int)(Math.random() * 500);
		String[] EncInString ={ "21811","17400","31222","2324","8314","1038","29695","3104","25564","29774","5126","31157","21028","9308","13091","11909","7485","9850","8850","7905","12336","24969","13739","14524","2343","781","27626","26023","13164","4390",
"15080","11478","24937","7318","30814","29976","9897","4800","25641","26338","20948","12197","21056","28228","26293","4073","29886","23793","14392","25291","17886","11323","8804","15408","4601","24338","25699","1688","8585","1036",
"6786","5414","808","22358","22567","21914","30095","1223","25056","8794","29082","2509","1877","13412","21571","14204","7503","13660","10403","21638","6074","29060","4595","24380","17311","10686","21903","28561","8488","1419",
"1264","14615","23966","9486","18351","11519","28014","21255","17800","15388","17951","22235","12373","14560","14429","26251","28174","22875","27120","14520","25294","22850","28612","13989","23248","15334","2018","20020","5229","11832",
"29555","25573","27166","2251","28868","25821","7295","29135","21820","30940","15433","7962","18279","21573","13399","14362","6381","10778","29600","22499","16538","15868","14146","12071","29782","5679","29812","17975","25389","19858",
"25234","24326","3913","1449","9493","30502","18417","30869","5527","27080","17299","11034","11730","12735","22966","16024","4513","19325","23813","25361","14588","14099","5451","26920","14846","6708","22896","29727","13026","561",
"18816","19416","21504","17917","10405","20180","2516","2090","22310","1078","18167","22761","27761","19903","28195","30732","28941","14802","23602","14087","14502","30064","4639","31466","23556","24124","32513","24168","21267","13432",
"27158","29650","11996","27909","31925","10012","29576","9063","27738","16341","4708","11198","17567","818","984","17612","20796","30210","365","27124","10252","16058","24526","17719","21257","10090","2246","16697","6734","16325",
"5438","15161","28179","7964","1856","21788","28851","18018","9205","26466","8362","8745","28073","4910","8847","11426","15813","29761","11037","12192","32467","29438","2350","9877","1663","13927","20412","16529","3983","13853",
"8162","586","21487","27746","4824","2062","18090","10266","17402","26576","28137","32453","31424","13092","23798","24197","29894","6459","20028","16414","20421","10470","23875","30960","5016","12951","24758","11518","23607","19041",
"25696","24808","9149","27125","17194","11252","11365","12967","24862","2560","2696","20327","1382","19856","20127","30407","21580","12742","20294","3323","26938","3171","4918","26067","4283","8138","23369","9922","8823","3325",
"19577","18649","31545","26012","14817","15050","5869","24044","3770","8937","19097","7886","22621","16678","7786","14275","28742","28947","18345","12526","17934","19428","17088","15632","18799","27240","3386","2956","29763","18196",
"32703","14948","29828","16376","18459","26681","30284","14535","823","26189","3543","23762","30492","2693","16763","269","27894","8542","13237","9735","11023","32765","27933","6645","3791","13861","18032","15014","18113","24630",
"29317","22414","11408","6451","10327","13248","16132","3261","27904","10220","15369","10519","32187","25700","23208","28962","23009","21275","9483","28257","27883","6563","29307","17142","22645","15149","358","23458","24120","23179",
"12625","16840","27150","7217","23784","3434","15346","10287","21493","30505","12797","19512","30051","2632","12904","15773","26939","30376","13711","31569","31399","717","28650","20454","4593","7638","7190","29581","20099","4488",
"25801","19993","16616","21570","28384","22780","17608","31496","853","8519","31470","19325","22848","27052","25413","28129","32732","27775","5847","16150","26756","15792","8652","17055","4274","19666","32110","13470","19453","1814",
"10794","15316","11810","6479","27015","15268","5371","20974","6193","17936","21120","8967","10224","11705","30412","17481","14768","14306","14874","29960" };
		String[] EncOutString ={ "927CB6B3AC5DF86D","362533CED4670BCD","278B33D344063B0E","23A5F8B131C005A7","BB9E9610F39A5075","8F7222FC73AF9C20","B192F75CB4BB12D8","6E76D71ED3ED3493","60D6237AA66EEF1B","3454FD49E7003012","D1593C3281CC88E5","924E5B97E36C76DF","2D063F7938148325","8C68AEBF7B6B19B1","C37138B6256C04E1","A29B72FB7E44D970","CD40851A1B3BFCA8","6D879375E4FE2D31","1381BFD43CA559ED","A3E8893610598931","989735392C73733E","7CF1BC2385FF6596","DD56FE510777048D","8A27EBDABDD764C1","1995936C920F77CD","E2C527866FC5C289","508926E5E24692DA","6C67A11EB0707D91","9358FEFE0C518E6C","0957FB887D2E03A5",
"CA5B6ED4AC61C0DB","7C624C0D4A954BC7","55E4B3DFD9287755","1160F4C1827F0B13","C2EE5A38E2336540","447D1829A8E38297","8AD4D89505395C0A","69EDC38B514F4CA5","CDC0F46C0F37E19B","CE98D961081AE756","AF332E92F8714973","47D96844D1DC9B3A","0C0EA4824E51DBB4","C56BC72ECA573BC3","FF6280F8617DDF30","030C700D39170663","CC5732EA93F175E1","0100049A2E4614B7","7E9656B2F3B9BC72","D7BC32F81479BF36","B918D0A245D9EE59","62FBF32132D2DADD","290D1991ED6DD1CC","251FEAAABB03A6A6","90740AE1F2BC86B6","1DC80EE9C8E8CAC2","51E2BA30A77858E3","1EA1109615775AE2","65C3548650C69A0C","FB8FF2AA82142D56",
"BC4F3EA24822143B","5442142345C1A1BF","AF733E65CE835A43","6C7C6A3A7B583EB5","C303EE59A52413A5","2781FAA8A400028C","3B80AC1174556D7A","88E20D2E42678952","A4F52EE32123BCD1","4A6D0640B363D37C","9ADA465CF5A4D435","49359A6F5B4B3D3E","3DC000FE8D72F7C8","E6D76580DAD27B4C","DB2FC49E040988BB","CCA0990EA047144A","0379743F21D5BA2C","7358904448368A96","B0FFA665DBE68E9F","37DCFE7E35A60117","8863A344BDCA2981","400251AFAC4F952E","42D16533153C2D68","73E0698E8BB58A25","6C4F8FE689B1E22C","1467283C843BBBE5","0B9C76241C867EAE","35BD929422074126","A02B21DD2DC6B7BB","1EEDE29ACF0BA801",
"5AC4009553DA5177","B0DB603BFBC24663","D7ABC301A4F11CD8","B0AF358DD16BDDD5","0F588C2A11D763FF","C179E856FA514718","C2D6AE6CFE6D4D56","2087FA29CEB49F6D","BBD434F3A87384C3","E04D452804A5CBD0","0E5961791DAB15CF","9AC282F67967C96F","9BC3A445A162C1F2","73D3C0E439F97737","973134A1BE400EB9","843C21A44142A58D","C413DA6AF5A1468D","CE841EFE20FF01AB","913E8A2329D3FF06","4E38B187DA51E3CB","8C0A16F7FADF2EBE","D585954336D70716","D57AF81DD97BB555","DFB8B17D2500E0AF","7CEDCF28F1ECBDDC","F42BF9CEB6F587F0","562BB968A1C6B554","740F2B589C14A924","470628EBEA18A5C9","F580F828D9622405",
"F8194F7E884C0A94","32BAFD8E4F7B03B3","A470EF2C8AE02D60","49E16D4FBF70FE2C","C26715F48EE1377C","A949A895F28FDCEC","76CCF801D649E16B","CEAE0F73395779FB","6CA3C4B32BCB93BA","03B381BF42608F88","3C37C4A9A6775A19","76E7983DD03E7CF3","77C8BD68A9AD39B2","28B02249CCAB247D","AF31A02414F836A5","D0F56211324DBC04","8CDDF52C904F8E2E","9E4D389D4B22DC9F","F2F865F252A4C843","847DCA1518EC43F4","6772B8B2A4D07E04","6E1CF3278ACB9923","06F2625C84661BEB","C3CF6307A4CD95BD","E70BB16F36E91C6F","3FC0AEBF85507FF1","D75DEB114B80586E","1FC6737F0FAF4D42","59D6C82036AF3AD2","7BCD3A7BF64DC89E",
"1AA250506082BEA6","738EAE69E618F0E5","667C314486E365B1","FCA96C7B490D0CFA","76BCA0CA1DC45E7C","FB3AC04E6BD26407","134626F88DB477A7","662694B6AFC67553","F1B01F2273E21CED","F32751E8506D0C56","5C1975A83B59E251","C600A902BAF48D81","FBD950CD96B8EC33","33DE7CA40E2F11C8","166B3A7B1EEC0A4F","3ECFD2DC81893DDF","5C05E8FBF5EF75CD","BD7C0081B5181788","29F08D1CE9DAAB2E","6006B89B99EE7CE8","E86753F81F674FA0","80E63ABF5AC0C76B","0E7BA753BA0BB94F","AF7D21C8BB5E0A82","F77FD3F7E5745056","3DE621C97B0549EC","9B345B4A1A04327B","FA35D54753697044","AB99AED0BDE31335","361A689738D5C2D0",
"71C704C7089A8349","0E823E823D746E61","E70CB5B107D442B2","4D776DA4BEB46C04","F004FF8F7BD45ADB","4E0B9210A0B720E3","E794B5670A315623","D163C03AE28AE9EF","11DDD344F3A8F48F","E652D813803FD716","4B2FE25FB3368378","4479139C4B77A263","0D8466997494E8B6","62ABC756B9BE3137","EBCDC20342A3AF85","77BE56CD69DD0F3D","C722518DA3B9B46B","513D2A8BAAC278BA","5AC589C5915674A6","FAAED8031AE6178C","C49F8F23D5817621","C21117FCAF7D0C01","AB5191A5C935A6A2","7B11D1F1D9777520","03484F3C132BBD7A","6FD9AA311D9EB8C4","2BDE2A91E529D425","EE8B50FA07D60484","FA3B416F11109B4D","91AE7530C245AFF9",
"827423A297093571","A4AEA9CEF2DD76B0","325171F25B220B52","D22E7A01343F9CF0","28BDF04F1B6FD901","5376AB5143058BA3","312E3655E03742AC","E7FEAB46934AFDAC","38189E72F3D08977","EF80981BBFA31E33","415039BD4E2DC9A3","0B67AE2BACD0ACA2","059313BD19D320D0","C6A8637EE0693D5F","C39355D360F752C5","7090475607FD6323","D456B783AE7D2423","66B7C822D8087DE8","82CDE752FDEF125B","8592A6EBDE6EC6FA","9010336290CDEEDF","13342EE9CBF281B6","A16A1AF882F7A83A","A2266389C2C257E9","1660110C076E56FC","B13C5947F31BEE33","928B924928FE31AD","1877F2D5F01C8AA4","2BF568B1FE26BF56","266A21C286F9AA09",
"79370CA6EE648DD7","D29B8169A15C2A6E","C430B8EB0BA0ADFE","C05ED538A3F578FC","861F0845848C702F","D0C4FB6B4D6C26D3","3DB16D886BDB3D9D","460EEC7E47D04EEC","75A4560336124AD4","D01C5BA6166A14B2","3784CDA48741292D","1057373A25B31E3E","BA74058EBEECB7FD","C0D127EBE5753102","264C5C44A960991A","AF2DC5210DCB64A5","CE52A2A57EF01558","26177A38CA6780A8","9C76A09BA9A9556A","4B815519FF121FD0","21F4BB1762A583B9","B293D67CDC7905DD","961A319AF94D85A5","0FAAE02AE2D9D9E2","2E6330F0D19590B0","27B22DBF154ACC34","6EB758CB01D0DA92","32F880D55EF1A465","BE374D6A6513D873","E730CEBCD532765E",
"ABEBDB5EC1BF6102","B2583661F66294B9","79887754BDB2B0BB","E4C5CBE08890F6EA","AEB5615E2A84364D","404EC09A7808AEFB","356CF7F965BDC298","0D26550EAC5A3990","9E6FE5D97B0C06EF","CE6AF10DE955141E","B847B86F998C81D6","CC1764F80C0D7BF8","F3F6BB2CF9768679","7B739745D927791B","A79A5EB6FA24B3B2","8EE24CBFC271D97C","7631A61410FA698C","6CAFBD336059A4CE","7575A58235C9F3D0","97E6CF7615AA115A","2EAE811D63AA65BC","ACEA8D837F47DB84","3A2068C21B29AACC","8C5735A22BBF120C","5BE8A4D2FC859B19","92271C6898BA2E66","6CD7B41466D009EC","8D5D8CDD4733254D","044344B705315413","2E531DB7AB6059F6",
"969AA5924702AA70","F9B4CF56580A7775","163CD36572536614","AAE3940806474A68","E0A2063EDA2F5E0B","F8F24D949C1023FF","2B7880A261C3C91A","86DE1D826CC015FE","515DFA0AEF0DAD74","38067CE506DAA315","621D12757C91FE2F","6719F6010979BBA1","0A472388DE1BC1AD","2D9C9BF19019D66A","970B17B6B89576DE","57A1C9B0379A907D","F07C1B9EB1CDBE34","D27B66CE49981216","8B2349B1729123D4","4E56205E7D6ABC4E","5868BA81B69D1F5D","4197D55906EC6879","64E31EF07D756929","AF89801DB6F55095","1E4D4CA21691C61C","684A5A6994C008F0","9DC17AC24DDA580B","A9D9EACA5F9A170F","5BB1946D3C2AD7E1","EC9CDAF97B9C48A7",
"0A6D3C60B320958A","26E90CC2F58996FD","ACA2D90221896236","18862A866B3ADACD","102074E89320ABAD","423C7756CFDB0582","08892AFDBC94E9AB","7206D1044717E910","08AED0D7B331E695","2EF324B5ED321578","26F5147087C9F13C","4A73A737F3FFCC20","5A696BBE296E3EE5","1C4B226EA5CA8809","80F01D46490219A6","BF21CCF32E60AFD4","5DCEDFEA27714474","203AE1B19615AF78","42D76056F2CD8946","5CE86D1FD2D11AB9","271264346BE8F62D","81D126FB53B596E9","14B6F941046C0D80","709671570A02B563","E1E7E520A78B485D","ECD3EA86D79DEDE7","83E073C8F1CA2CF7","4EE4AD429634D8D0","65331D73E9822F25","B81D142FC13D3858",
"0A9758BC71A2B327","FBFCF92BBD6E44AE","8795C886CD65AF7A","70427923173784BC","6E1469834ABC7939","FC2454C566441D55","B744C8D3AB798ABE","C07F109DF906326D","DB740934F86758F7","397E1EC320BB343B","611F2EC79DBDCC71","C26D287F9AD9B44F","CF9BB7BC765AD2F1","6FB94FE9815A340C","1A4BB09FCA5C7A5A","4CA787132D97CEC5","3EB542976E852AA6","47B5F52F43FF4600","48D22E53EC64908E","6741C8DAFF0F8B63","C9ED7BF9D4D9F735","D395B4FBFFB44E7F","CC788AED9E848C2E","83019B6BC1E4DADD","AA8122AE4DBB594F","01ACEA59EA1E8090","09BBAC0CA588474F","8B6F6698D34376D5","11F950DB8BD86F98","4E55781B2A9B5AF9",
"5DF56602157866B0","CB172799176B1A9C","2BD76D82931C38B9","BD3BC7317D59923F","591AEC450DF52CC3","7E33DDD5523E22B2","0837A708BD74A09E","63AAE5E3EE1AB292","AD4D0EDE1CD31EAE","BE712E0C363E53E4","3709B593A233D311","2E14FE9D35C06F1B","38E8B1BD42D0B27B","F1DB1D7F24EF38EA","A028E4BD376C52A0","C40DA4A9F6DA8C22","3C0DA76747B8B65D","4AD83393E203731B","E57EFDF49F5E50EF","F48291B5E5E0EC66","2B8D04808A731CD1","4D53062D3D8F64A1","66F8CBF9AD87634A","BC8445D182F28A54","B6CFCC137ECCC708","F5D29392D2E4A0FC","8CEDC066F45FC88B","6E965F9E8BD9E338","C4BE42D53045CB92","A0ADF8C6A1293D5A",
"C89144C7B41126A1","D9E85B09C469A846","882E8CDEA02F5976","D39387FD3166C88B","D3996C907FBEC5BF","1C38D3CF1D4FEDE6","8F8CC6C4372455DB","BCE856CCB07A9BC3","5DE7B447E0D929D0","2295A86817CCB19D","1CBC06EBB3157468","4F0C39FB49F97615","0DDD8CF064586FC9","1FD2C2B300D836B5","E78BDB45ECC21F35","B6974FDB40A977B8","0FA5058BEDA7AAB0","CFD65997D4AF1D06","48DA4865162D5AAF","A00B4D9113B2FE18","77BC3888489C0E7E","03C2BDE81D2B99FB","416CDA1C85AD9E0D","89936EA24165FC01","1D266D8D2E5C7A31","356330E7BD4A2D5F","9509D3A33336E48F","702A8416C28447AE","278A7320943E2F34","5FDB9C841C79C515",
"08BC46FC0D4F5B4B","36621DE024093837","448FE0770F2AC9E0","C80A15C255E50319","5DBF481AF60BC9C5","61212FA8471534B1","85D13E723F1F5D9B","592825917F9B414B","BD15B690085DEF88","990A2A8083F3C52A","35237B1E1F0969F0","BD7C0081B5181788","5A7C74F404CA10C2","5951CEFC4AA3DBE2","D57F7516CA3D4E5A","BEAF8A6CAF86DC74","57628FD557BCE827","A5FF9C9BC557AAE5","0CFA8995DB5687E2","13114805D1D8F06A","07455E9556345B10","3A5303838EF44255","C63CF3F7027E99E4","2C955E04C568E873","78AAC4883E56A32D","BE03C91A039C00E7","DD79E71233AF614F","F35F03A75238BB55","0EFCA682C58E5D60","555421E14966D054",
"0B2CF757E658CC7B","676D45F13EFDFC39","B22A4B45399232DA","6AE9C6AC46BBDD44","18777598709B53B7","CC06DA3B74F1BC77","C52E7670E46DAA9E","3259889B797AB774","C07F2A5FDD1F9A21","BD38FD66B0BAF2C6","1D9C0142C0026785","AC60BED6F453497F","770802336209E20B","F9BB5ACB92815C0D","D1B76A454E68E0CD","77FFDCB4B293BFB6","8CECA16C5CAF89BD","D5A6421B1F2855EB","374E0FB30033446A","BD4C5AAA9BA33AFE" };



		for (n = 0; n < 255; n++)
		{
			DevicePath = j9.FindPort(n);
			if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			outString = j9.EncString_New(EncInString[myrnd], DevicePath);
			j9.CloseUsbHandle(DevicePath);
			if ((j9.get_LastError() == 0) && (outString.compareTo(EncOutString[myrnd]) == 0))
			{
				return 0;
			}
		}
		return -92;
	}


}
